home *** CD-ROM | disk | FTP | other *** search
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "ctype.h"
- #include "werr.h"
- #include "bbc.h"
-
- #define mtnl 50
- #define mcl 8
-
- extern struct std {
- char town[mtnl];
- char code[mcl];
- struct std *next;
- struct std *previous;
- } *stdstart,*stdlast;
-
- extern int modified;
-
- void add_entry(char *town,char *code)
- {
- char *to_capitals(char *string);
- struct std *add_sorted(struct std *stdnode,struct std *stdstart);
- struct std *stdnode;
- if ((stdnode = (struct std *)
- calloc(1, sizeof(struct std))) == NULL)
- { werr(0,"Unable to assign memory for new node.\n");return;}
-
- strncpy(stdnode->town,to_capitals(town),mtnl-1);
- strncpy(stdnode->code,code,mcl-1);
-
- stdstart = add_sorted(stdnode,stdstart);
- modified++;/*bbc_vdu(7)*/;
- }
-
- struct std *add_sorted(struct std *stdnode,struct std *stdstart)
- {
- struct std *old,*temp;
- temp = stdstart;
- old = NULL;
-
- while (temp) {
- if (strcmp (temp->town,stdnode->town)<0) {
- old = temp;
- temp = temp->next;
- }
- else {
- if (temp->previous) { /* then add in the middle of the list as is not NULL */
- temp->previous->next = stdnode;
- stdnode->next = temp;
- stdnode->previous = temp->previous;
- temp->previous = stdnode;
- return stdstart; /* return the original start */
- } /* insert a new first element */
- stdnode->next = temp;
- stdnode->previous = NULL;
- temp->previous = stdnode;
- return stdnode; /* new start pointer */
- }
- }
- old->next = stdnode; /* else add onto the end */
- stdnode->next = NULL;
- stdnode->previous = old;
- stdlast = stdnode;
- return stdstart; /* return the original start */
-
- }
-